<?php
/**
 * Dao of Agent
 *
 * @author fsqijy
 */


require_once BaseUtil::getModulePath("base") . '/models/BaseDao.php';

class AgentDao extends BaseDao{

    protected $_name;
    private $userTable;
    private $regionTable;
    private $campusesTable;
    public function  _setup() {
        $this->_name = $this->prefix() . "apply_school_actings";
        $this->userTable = $this->prefix() . "users";
        $this->regionTable = $this->prefix() . "area_dicts";
        $this->campusesTable = $this->prefix() . "agent_campuses";
        parent::_setup();
    }
    public function getAgentDetailByID($id){
        $select = $this->db_r->select();
        $select->from($this->_name,"*");
        $select->join($this->userTable,"$this->userTable.id = $this->_name.user_id",array('name','campus_id','parent_id','certf'));
        $select->joinLeft("$this->userTable as deputy","deputy.id = $this->userTable.parent_id",array('name as deputyname'));
        $select->joinLeft($this->campusesTable,"$this->campusesTable.id = $this->userTable.campus_id",array('area_name'));
        $select->joinLeft("$this->regionTable as r1","r1.id = $this->_name.delivery_address_1",array('title as sheng'));
        $select->joinLeft("$this->regionTable as r2","r2.id = $this->_name.delivery_address_2",array('title as shi'));
        $select->joinLeft("$this->regionTable as r3","r3.id = $this->_name.delivery_address_3",array('title as qu'));
        $select->where("$this->_name.is_delete = 0");
        $select->where("$this->_name.id = ? ",$id);
        $select->order("$this->_name.created DESC");
        $sql = $select->__toString();
        return $this->db_r->fetchRow($sql);
    }
    public function getAgentByID($agentID){
        $select = $this->db_r->select();
        $select->from($this->_name);
        $select->where("is_delete = 0");
        $select->where("id = ? ",$agentID);
        $sql = $select->__toString();
        return $this->db_r->fetchRow($sql);
    }
    public function updateAgent($set,$id){
         $where = $this->db_w->quoteInto('id = ?', $id);
         $this->updateData($set,$where);
    }
}
